package cn.meng.base.handler;

import cn.hutool.http.HttpUtil;
import cn.meng.base.usedConst.NoticeConst;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

/**
 * 公众号消息推送消费者
 * @author 万梦辉
 */
@Component
public class WeChatMessageCustomer {

    private HashMap<String,Object> params = new HashMap<>();
    private final Logger log = LoggerFactory.getLogger(this.getClass());

    @RabbitListener(queues = {"weChat.fanout.queue"})
    public void handleWeChatMessage(Map message) {
        params.put("token",NoticeConst.TOKEN);
        //指定发送的群组
        params.put("channel",NoticeConst.CHANNEL);
        params.put("webhook",NoticeConst.WEBHOOK);
        params.put("title",message.get("title"));
        params.put("content",message.get("content"));
        HttpUtil.post(NoticeConst.URL,params);
        log.info("微信公众号信息发送成功");
    }

}
